<template>
  <a-config-provider :locale="locale">
    <DBheader />
    <router-view />
    <DBfooter />
  </a-config-provider>
</template>
<script>
import DBheader from './components/DBheader.vue';
import DBfooter from './components/DBfooter.vue'
import { message } from 'ant-design-vue';
import zhCN from 'ant-design-vue/es/locale/zh_CN';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
dayjs.locale('zh-cn');

export default {
  components: {
    DBheader,
    DBfooter
  },
  data() {
    return {
      isOnline: window.navigator.onLine,
      locale: zhCN,
    }
  },
  mounted() {
    // 监听 online 事件
    window.addEventListener('online', this.handleNetworkChange)
    // 监听 offline 事件
    window.addEventListener('offline', this.handleNetworkChange)
  },
  beforeUnmount() {
    // 移除事件监听器
    window.removeEventListener('online', this.handleNetworkChange)
    window.removeEventListener('offline', this.handleNetworkChange)
  },
  methods: {
    // 处理网络连接状态变化
    handleNetworkChange() {
      this.isOnline = window.navigator.onLine
      console.log(`当前网络连接状态：${this.isOnline ? '已联网' : '未联网'}`)
    }
  },
  created() {
    if (!!window.WebSocket && window.WebSocket.prototype.send) {
      console.log("Websocket-ok")
    }
    else {
      message.error("您的浏览器不支持Websocket通信协议，请使用Chrome或者Firefox浏览器！")
    }
  }
}

</script>